<!DOCTYPE html>
<html>
<head>
    <title>Physics Diagram of an Object on an Inclined Plane</title>
</head>
<body>
<canvas id="physicsCanvas" width="500" height="500" style="border:1px solid #000000;"></canvas>
<script>
    const canvas = document.getElementById('physicsCanvas');
    const ctx = canvas.getContext('2d');

    // Helper function to draw a vector with an arrowhead
    function drawArrow(ctx, fromX, fromY, toX, toY) {
        const headLength = 15; // length of head in pixels
        const dx = toX - fromX;
        const dy = toY - fromY;
        const angle = Math.atan2(dy, dx);

        ctx.beginPath();
        ctx.moveTo(fromX, fromY);
        ctx.lineTo(toX, toY);
        ctx.lineTo(toX - headLength * Math.cos(angle - Math.PI / 6), toY - headLength * Math.sin(angle - Math.PI / 6));
        ctx.moveTo(toX, toY);
        ctx.lineTo(toX - headLength * Math.cos(angle + Math.PI / 6), toY - headLength * Math.sin(angle + Math.PI / 6));
        ctx.stroke();
    }

    // --- Parameters ---
    const angleDeg = 36.9;
    const angleRad = angleDeg * Math.PI / 180;
    const gForceLabel = "10 N";

    // --- Drawing Styles ---
    ctx.strokeStyle = 'black';
    ctx.fillStyle = 'black';
    ctx.lineWidth = 2.5;
    ctx.font = 'bold 24px sans-serif';
    ctx.textAlign = 'center';
    ctx.textBaseline = 'middle';

    // --- Draw Incline and Base ---
    const inclineStartX = 50;
    const inclineStartY = 420;
    const inclineLength = 430;
    const inclineEndX = inclineStartX + inclineLength * Math.cos(angleRad);
    const inclineEndY = inclineStartY - inclineLength * Math.sin(angleRad);

    // Base line
    ctx.beginPath();
    ctx.moveTo(inclineStartX, inclineStartY);
    ctx.lineTo(inclineEndX, inclineStartY);
    ctx.stroke();

    // Inclined plane
    ctx.beginPath();
    ctx.moveTo(inclineStartX, inclineStartY);
    ctx.lineTo(inclineEndX, inclineEndY);
    ctx.stroke();

    // --- Draw Angle Arc and Label ---
    ctx.beginPath();
    ctx.arc(inclineStartX, inclineStartY, 70, 0, -angleRad, true);
    ctx.stroke();
    // Angle value
    ctx.fillText(angleDeg.toString(), inclineStartX + 120, inclineStartY - 30);
    // Degree symbol
    ctx.font = 'bold 16px sans-serif';
    ctx.beginPath();
    ctx.arc(inclineStartX + 155, inclineStartY - 38, 4, 0, 2 * Math.PI);
    ctx.stroke();
    ctx.font = 'bold 24px sans-serif';


    // --- Draw the Object (Circle) ---
    const objDistAlongIncline = 300; // distance from the bottom
    const objRadius = 25;
    const objCenterX = inclineStartX + objDistAlongIncline * Math.cos(angleRad);
    const objCenterY = inclineStartY - objDistAlongIncline * Math.sin(angleRad);

    ctx.beginPath();
    ctx.arc(objCenterX, objCenterY, objRadius, 0, 2 * Math.PI);
    ctx.fill();

    // --- Draw Gravity Vector ---
    const gravityVecLength = 110;
    const gravityVecStartX = objCenterX;
    const gravityVecStartY = objCenterY;
    const gravityVecEndX = gravityVecStartX;
    const gravityVecEndY = gravityVecStartY + gravityVecLength;

    drawArrow(ctx, gravityVecStartX, gravityVecStartY, gravityVecEndX, gravityVecEndY);
    ctx.fillText(gForceLabel, gravityVecEndX + 45, gravityVecStartY + gravityVecLength / 2);

    // --- Draw Coordinate Axes ---
    const axisDistAlongIncline = 150; // distance of axis origin from the bottom
    const axisLength = 80;
    const axisOriginX = inclineStartX + axisDistAlongIncline * Math.cos(angleRad);
    const axisOriginY = inclineStartY - axisDistAlongIncline * Math.sin(angleRad);

    // +x axis (down the incline)
    // Angle with horizontal is -angleRad because it points down
    const xAxisAngle = -angleRad;
    const xAxisEndX = axisOriginX + axisLength * Math.cos(xAxisAngle);
    const xAxisEndY = axisOriginY - axisLength * Math.sin(xAxisAngle); // minus because canvas y is inverted
    drawArrow(ctx, axisOriginX, axisOriginY, xAxisEndX, xAxisEndY);
    ctx.fillText('+x', axisOriginX - 35, axisOriginY + 20);

    // +y axis (perpendicular to incline, pointing "out")
    // Angle with horizontal is 90 degrees CCW from the UP-incline vector, so angle is (angleRad + 90deg)
    const yAxisAngle = angleRad + Math.PI / 2;
    const yAxisEndX = axisOriginX + axisLength * Math.cos(yAxisAngle);
    const yAxisEndY = axisOriginY - axisLength * Math.sin(yAxisAngle);
    drawArrow(ctx, axisOriginX, axisOriginY, yAxisEndX, yAxisEndY);
    ctx.fillText('+y', yAxisEndX + 30, yAxisEndY);

</script>
</body>
</html>